package bg.cinema_system.beans;

import java.sql.SQLException;
import java.text.ParseException;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import bg.cinema_system.pojo.Movie;
import bg.cinema_system.pojo.Projection;
import bg.cinema_system.service.UserServeice;

@ManagedBean
@SessionScoped
public class StaffBean {

	private String type;
	private String warning;
	private String message;

	private Movie moviePojo;
	private Projection projection;

	public StaffBean() {
		type = "projection";
		moviePojo = new Movie();
		projection = new Projection();
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;

		this.warning = null;
		this.message = null;
	}

	public boolean isMovie() {
		return type.equals("movie") ? true : false;
	}

	public String getWarning() {
		return warning;
	}

	public void setWarning(String warning) {
		this.warning = warning;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Movie getMoviePojo() {
		return moviePojo;
	}

	public void setMoviePojo(Movie moviePojo) {
		this.moviePojo = moviePojo;
	}

	public Projection getProjection() {
		return projection;
	}

	public void setProjection(Projection projection) {
		this.projection = projection;
	}

	public String insertMovie() {
		boolean isMessgaDisplay = true;
		try {
			UserServeice.insertMovie(getMoviePojo());
		} catch (SQLException e) {
			isMessgaDisplay = false;
			this.message = null;
			setWarning("Movie does not inserted. Try again!");
			e.printStackTrace();
		} catch (ParseException e) {
			isMessgaDisplay = false;
			this.message = null;
			setWarning("Movie does not inserted. Try again!");
			e.printStackTrace();
		}
		if (isMessgaDisplay) {
			this.warning = null;
			setMessage("Successfully added movie.");
		}
		return "staff";
	}

	public String insertProjection() {
		boolean isMessgaDisplay = true;
		try {
			UserServeice.insertProjection(projection);
		} catch (SQLException e) {
			isMessgaDisplay = false;
			this.message = null;
			setWarning("Projection does not inserted. Try again!");
			e.printStackTrace();
		} catch (ParseException e) {
			isMessgaDisplay = false;
			this.message = null;
			setWarning("Projection does not inserted. Try again!");
			e.printStackTrace();
		}
		if (isMessgaDisplay) {
			this.warning = null;
			setMessage("Successfully added projection.");
		}
		return "staff";
	}

}
